/**
 * Created with IntelliJ IDEA.
 * ClassName: TestRecursion
 * Package: PACKAGE_NAME
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-06-20
 * Time: 17:05
 */

public class TestRecursion {
    public static void main(String[] args) {
        //实现阶乘
        System.out.println(factorial(5));

        System.out.println(fact(4));
    }
    public static int factorial(int n){
        int result = 1;
        for (int i = 1; i <= n; i++) {
            result = result * i;
        }
        return  result;
    }

    //递归
    public static int fact(int n){
        //一定要有界限
        if (n == 0) return 1;
        return fact(n-1) * n;
    }

}
